
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
int main()
{
	int pid = fork();//创建子进程
	if (pid < 0)
	{
		printf("子进程创建失败\n");
		exit(0);    
	}
	else if (pid == 0)
	{
		int cnt = 10;
		while (cnt)
		{
			printf("子进程运行中,Pid: %d\n", getpid());
			sleep(2);  
			cnt--;
		}
		exit(0);
	}
	else
	{
	//int option = wait(NULL);
	
		while (1) {
			printf("父进程开始运行,Pid: %d\n", getpid());
			sleep(2);
		}
	}
	return 0;
}
